/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_cicsts_header_unpack.c                           */
/*  NOTE      =                                                    */
/*  DATE      = 2016/05/03 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>

#include "frcomm.h"

#include <cicsts/config.h>
#include <cicsts/cicsts_core.h>
#include <cicsts/cicsts_header.h>
#include <cicsts/cicsts_comm.h>
#include <apmtest_comm.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    char *p_bin = (char *) "000002360000107b000b90a0270502ff0003d1004004c3d7d4c9180b02c3c9c3e2e4e2c5d940400b01bf000000000000000000020312f20a8502020102000001040e430e02000007e0000000800100000a02a2968194818995000504200001d8063c3f786d6c2076657273696f6e3d22312e30223f3e3c54726164653e3c526571756573744865616465723e3c627573696e65737341636365707449643e373630323031363034323033333835323830333c2f627573696e65737341636365707449643e3c73657269616c4e756d6265723e303c2f73657269616c4e756d6265723e3c76657273696f6e3e312e303c2f76657273696f6e3e3c636d64547970653e303c2f636d64547970653e3c7265717565737465723e545359573c2f7265717565737465723e3c6368616e6e656c3e435a42303c2f6368616e6e656c3e3c7265717565737454696d655374616d703e323031362d30342d32302031313a33343a33312e3030303330313c2f7265717565737454696d655374616d703e3c6f7267616e697a6174696f6e556e697449642f3e3c74656c6c6572313e747379773c2f74656c6c6572313e3c74656c6c6572323e747379773c2f74656c6c6572323e3c7365727669636549643e68715a4858583c2f7365727669636549643e3c2f526571756573744865616465723e3c426f64793e3c7a686c786d2f3e3c7a683e333031303030303031303132303130303032383332383c2f7a683e3c7a6878682f3e3c6a676d2f3e3c2f426f64793e3c2f54726164653e";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CicsTS_header st_cicsts_header;
    memset(&st_cicsts_header, 0x00, sizeof(st_cicsts_header));

    CU_ASSERT_EQUAL(cicsts_header_unpack(FR_YES, arr_payload, strlen(p_bin) / 2, &st_cicsts_header), FR_SUCC);
    CU_ASSERT_EQUAL(st_cicsts_header.ui_msg_id, 0x107b);
    CU_ASSERT_EQUAL(st_cicsts_header.ui_header_len, 97);
    CU_ASSERT_EQUAL(st_cicsts_header.ui_pkt_len, 0x236);
}

int add_suite_cicsts_header_unpack(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" cicsts_header_unpack()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
